<template>
  <a-card :bordered='false' v-show='isAchClassSubjectProjScoreListCompShow'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :xl='3' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='年级' prop='queryParam.gradeId'>
              <!--              v-model="queryParam.gradeId"  对应java的Controller的接收参数vo对象的属性gradeId的值 -->
              <j-dict-select-tag  @change='changeGradeId' v-model='queryParam.gradeId' placeholder='请选择年级'
                                 dictCode='cou_grade,grade_name,id,tenant_id  is not null order by  grade_order' />
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="6">选中值：{{ formData.gradeId}}</a-col>-->
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='考试' prop='queryParam.examinationId'>
              <j-dict-select-tag @change='changeExaminationId' v-model='queryParam.examinationId' placeholder='请选择考试'
                                 :dictCode='queryParamSelect.examinationIdSelect' />
            </a-form-model-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='计分范围(多选)' prop='queryParam.achievementStatus'>
              <j-multi-select-tag
                v-model='queryParam.achievementStatus'
                dictCode='achievement_status'
                placeholder='请选择'>
              </j-multi-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='试卷' prop='queryParam.examinationPaperId'>
              <!--                  <j-select-multiple v-model="queryParam.examinationPaperId" :options="jSelectExaminationPaperId"/>-->
              <j-dict-select-tag @change='changeExaminationPaperId' v-model='queryParam.examinationPaperId'
                                 :dictCode='queryParamSelect.examinationPaperIdSelect' />
            </a-form-model-item>
          </a-col>
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <!-- 取试卷的标准 或考试的标准 -->
            <a-form-model-item label='题型' prop='queryParam.examPaperProjectItemId'>
              <j-dict-select-tag @change='changeExamPaperProjectItemId' v-model='queryParam.examPaperProjectItemId'
                                 :dictCode='queryParamSelect.examPaperProjectItemIdSelect' />
            </a-form-model-item>
          </a-col>

          <!--              <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
          <!--                &lt;!&ndash; 取试卷的标准 或考试的标准 &ndash;&gt;-->
          <!--                <a-form-model-item label="评分标准" prop="queryParam.achiStandPurposeType">-->
          <!--                  <j-dict-select-tag @change='changeAchiStandPurposeType' v-model="queryParam.achiStandPurposeType"  :dictCode="queryParamSelect.achiStandPurposeTypeSelect"/>-->
          <!--                </a-form-model-item>-->
          <!--              </a-col>-->
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='评分标准' prop='queryParam.achiStandPurposeType'>
              <!--                <j-dict-select-tag @change='changeAchievementStandardId' v-model="queryParam.achievementStandardId"  :dictCode="queryParamSelect.achievementStandardIdSelect"/>-->
              <j-multi-select-tag
                v-model='queryParam.achiStandPurposeType'
                dictCode='achi_stand_purpose_type'
                placeholder='请选择'>
              </j-multi-select-tag>
            </a-form-model-item>
          </a-col>


          <a-col :xl='3' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='评分段位' prop='queryParam.achieveStandardItemId'>
              <!--                  <j-select-multiple v-model="queryParam.standItemId" :options="jSelectstandItemId"/>-->
              <j-dict-select-tag v-model='queryParam.achieveStandardItemId'
                                 :dictCode='queryParamSelect.achieveStandardItemIdSelect' />
            </a-form-model-item>
          </a-col>
          <!--              <a-col :span="12">多选下拉框(v-model)：{{ queryParam.examinationPaperId }}</a-col>-->
          <a-col :xl='5' :lg='7' :md='8' :sm='24'>
            <a-form-item label='成绩均值范围' prop='queryParam.achievementScore'>
              <label >[</label>
              <a-input-number label='成绩均值范围:[' v-model='queryParam.achievementScore_min'></a-input-number>
              <label >-</label>
              <a-input-number label='-' v-model='queryParam.achievementScore_max'></a-input-number>
              <label >)</label>

            </a-form-item>

          </a-col>

        </a-row>
        <a-row>
          <a-col :offset='8'>
            <span style='overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
            </span>
          </a-col>
        </a-row>

      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type='primary' icon='download' @click="handleExportXls('班级考试分项成绩分析表')">导出</a-button>
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--    //动态列 script 3 //////////////////////////////////////////////////////////////////////////////////////////////////////////-->
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>

        <span style='float:right;'>
          <a @click='loadDataTrRow2Col()'><a-icon type='sync' />刷新</a>
          <a-divider type='vertical' />
          <a-popover title='自定义列' trigger='click' placement='leftBottom'>
            <template slot='content'>
              <a-checkbox-group @change='onColSettingsChange' v-model='settingColumns' :defaultValue='settingColumns'>
                <a-row style='width: 400px'>
                  <template v-for='(item,index) in defColumns'>
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                        <a-col :span='12'><a-checkbox :value='item.dataIndex'><j-ellipsis :value='item.title'
                                                                                          :length='10'></j-ellipsis></a-checkbox></a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type='setting' />设置</a>
          </a-popover>
        </span>
      </div>
      <!--    //动态列 script 3 //////////////////////////////////////////////////////////////////////////////////////////////////////////-->

      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <!--    <ach-class-subject-proj-score-modal ref="modalForm" @ok="modalFormOk"></ach-class-subject-proj-score-modal>-->
    <!--    <get-row-to-columns :url='this.url.list'-->
    <!--                        :params='this.queryParam'-->
    <!--                        :gudingColumns='this.gudingColumns'-->
    <!--                        :dongtaiColumns='this.dongtaiColumns'-->
    <!--                        ref='achClassSubjectProjScore'>-->
    <!--    </get-row-to-columns>-->
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import achClassSubjectProjScoreModal from './modules/AchClassSubjectProjScoreModal'
import getRowToColumns from '../components/public/getRowToColumns'
import { getSubjectList, queryTeacherListBySubject } from '@api/commonAPI'
import Vue from 'vue'
import { getAction } from '@api/manage'
import { deepClone } from '@/utils/util'

export default {
  name: 'AchClassSubjectProjScoreListComp',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    achClassSubjectProjScoreModal,
    getRowToColumns
  },
  props: {
    isAchClassSubjectProjScoreListCompShow: false,
    classIdNew: {
      type: String,
      default: ''
    },
    gradeCode: {
      type: String,
      default: ''
    },
  },
  watch: {
    classIdNew: {
      immediate: true,
      handler() {
        if(this.classIdNew){
          this.queryParam.classId = this.classIdNew
          this.searchQuery()
        }
      }
    },
    gradeCode: {
      immediate: true,
      handler() {
        if(this.gradeCode){
          this.queryParam.gradeId = this.gradeCode
          this.isDisabled = true;
          this.changeGradeId();
          this.searchQuery()
        }
      }
    }
  },
  data() {
    return {
      isDisabled: false,
      description: 'ach_class_subject_proj_score管理页面',
      disableMixinCreated : true, //默认初始状态不加载数据
      queryParam: {
        achievementStatus: '1,2,3'
      },
      //查询条件联动部分定义
      queryParamSelect: {
        examinationIdSelect: 'ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 order by create_time  desc',
        classIdSelect: 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 order by  class_order',
        examinationPaperIdSelect: 'ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0  order by examination_paper_name',
        subjectIdSelect: 'cou_subject cs,cs.subject_name,cs.id,cs.del_flag  =0 order by cs.subject_order',
        examPaperProjectItemIdSelect: 'ach_exam_paper_project_item,exa_pap_pro_item_name,id,1=2 order by exa_pap_pro_item_order'
      },

      //动态列 script 2 ////////////////////////////////////////////////////////////////////////////////////////////////
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      defColumns: [],
      //列定义 defColumns
      gudingColumns: [

        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '年级',
          align: 'center',
          dataIndex: 'gradeName'
        },
        {
          title: '班级',
          align: 'center',
          dataIndex: 'className'
        },
        {
          title: '班级简称',
          align: 'center',
          dataIndex: 'classNickname'
        },
        {
          title: '考试',
          align: 'center',
          dataIndex: 'examinationName'
        },
        {
          title: '试卷',
          align: 'center',
          dataIndex: 'examinationPaperName'
        },
        {
          title: '科目',
          align: 'center',
          dataIndex: 'subjectName'
        },
        {
          title: '题型',
          align: 'center',
          dataIndex: 'exaPapProItemName'
        },
        {
          title: '满分',
          align: 'center',
          dataIndex: 'exaPapProItemFullMarks'
        },
        {
          title: '班级总人数',
          align: 'center',
          dataIndex: 'classStudentAllCount'
        },
        {
          title: '计分(参考)人数',
          align: 'center',
          dataIndex: 'classStudentExamCount'
        },
        {
          title: '班级平均分',
          align: 'center',
          dataIndex: 'avgClassAchiSubjProjItemScore'
        },
        {
          title: '标准差(越大越波动)',
          align: 'center',
          dataIndex: 'stddevClassAchiSubjProjItemScore'
        },
        {
          title: '平均得分率(%)',
          align: 'center',
          dataIndex: 'classAchiSubjProjItemScorePercentage'
        },
        {
          title: '年级排名',
          align: 'center',
          dataIndex: 'rankAvgClass'
        }
        // ,
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   fixed:"right",
        //   width:147,
        //   scopedSlots: { customRender: 'action' }
        // }


      ],
      dongtaiColumns: [

        {
          title: '段位',
          align: 'center',
          dataIndex: 'standItemAliasname',//列名所在字段
          dataIndexId: 'standItemId',     //绑定数据字段(用于区分唯一列名的id，一般是列名对应的id值）
          nulldatacolname: '其他',        //空值默认值设置（如果列名为空的时候，设置为其他）
          valueIndex: 'analysisYlrs',      //数据值取值字段（对应动态列中显示的数据）
          valueIndexsuffix: '人',         //数据值的后缀单位或符号
          subColumns: [
            //预留动态列多列分组展示，暂未实现，后期优化
            {
              title: '班级优良人数',
              align: 'center',
              dataIndex: 'analysisYlrs'
            },
            {
              title: '班级优良率',
              align: 'center',
              dataIndex: 'analysisYlv'
            },
            {
              title: '优良率排名',
              align: 'center',
              dataIndex: 'rankYlvClass'
            }

            // {
            //   title:'标准',
            //   align:"center",
            //   dataIndex: 'achievementStandardName'
            // },
            // {
            //   title:'标准应用类型',
            //   align:"center",
            //   dataIndex: 'achiStandPurposeType_dictText'
            // },
            // {
            //   title:'段位',
            //   align:"center",
            //   dataIndex: 'standItemName'
            // },
            // {
            //   title:'段位简称',
            //   align:"center",
            //   dataIndex: 'standItemAliasname'
            // },

          ]
        }

      ],
      //动态列 script 2 ////////////////////////////////////////////////////////////////////////////////////////////////
      url: {
        list: '/analysisachievement/achclasses/achClassSubjectProjScore/list',
        // delete: "/analysisachievement/achclasses/achClassSubjectProjScore/delete",
        // deleteBatch: "/analysisachievement/achclasses/achClassSubjectProjScore/deleteBatch",
        exportXlsUrl: '/analysisachievement/achclasses/achClassSubjectProjScore/exportXls'
        // importExcelUrl: "analysisachievement/achclasses/achClassSubjectProjScore/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
      classId: '',
      subjectId: '',
    }
  },
  created() {

    this.initColumns()
    //动态列 script 4 /////////////////////////////////////////////////////////
    //   this.loadDataTrRow2Col();
    //   this.initColumns();
    //动态列 script 4 /////////////////////////////////////////////////////////
    // this.getSuperFieldList();
  },
  mounted() {
    this.$bus.$on('isAchClassSubjectProjScoreListCompShow', (val) => {
      console.log('拿到了老師關聯的班級信息')
      console.log(val)
      this.queryParam.classId = val.returnClassId
      this.queryParam.subjectId = val.returnSubjectId
      this.searchQuery()
    })

    this.$bus.$on('projScoreList', (val) => {
      console.log(val)
    })
    // this.$refs.achClassSubjectProjScore.loadDataTrRow2ColNew()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []

      this.superFieldList = fieldList
    },
    //查询条件联动begin //////////////////////////////////////////////////////////////
    //初始化科目信息
    async initsubjectList() {
      let subjectList = await getSubjectList()
      if (subjectList.code === 200) {
        this.subjectList = []
        subjectList.result.forEach(item => {
          this.subjectList.push({
            label: item.subjectName,
            value: item.subjectId
          })
        })
      }
    },
    //科目变更-->更新教师列表
    async handleSubjectChange() {
      let tenantId = ''
      if (localStorage.length > 0) {
        let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
        tenantId = localData.value.tenantId
        this.queryParam.tenantId = tenantId
      }
      let params = {
        tenantId: tenantId,
        subjectId: this.queryParam.subjectId
      }
      this.getTeacherLists(params)
    },
    //初始化教师
    async getTeacherLists(params) {
      var teaparams
      if (params) { //如果参数存在
        teaparams = params
      } else { //如果参数不存在
        let tenantId = ''
        if (localStorage.length > 0) {
          let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
          tenantId = localData.value.tenantId
          this.queryParam.tenantId = tenantId
        }
        teaparams = {
          tenantId: tenantId,
          subjectId: null
        }
      }

      let res = await queryTeacherListBySubject(teaparams)
      if (res.success) {
        this.teacherList = []
        res.result.forEach(item => {
          this.teacherList.push({
            value: item.teacherId,
            label: item.teacherName
          })
        })
      }
    },
    //更改年级-->选择考试，选择班级
    changeGradeId() {
      if (this.queryParam.gradeId) { //判断不为空
        this.queryParamSelect.examinationIdSelect = 'ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and grade_id=\'' + this.queryParam.gradeId + '\' order by create_time  desc'
        this.queryParamSelect.classIdSelect = 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code=\'' + this.queryParam.gradeId + '\' order by  class_order'
      }
    },
    //更改考试-->选择试卷
    changeExaminationId() {
      if (this.queryParam.examinationId) {
        this.queryParamSelect.examinationPaperIdSelect = 'ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0 and aep.examination_id =\'' + this.queryParam.examinationId + '\'  order by aep.examination_paper_name'
        // this.queryParamSelect.achievementStandardIdSelect = "ach_achievement_standard,achievement_standard_name,id,iz_open =1 and del_flag =0  order by achievement_standard_order",
        // this.queryParamSelect.examinationIdSelect = "ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and grade_id='"+ this.queryParam.gradeId +"' order by create_time  desc"
      }
    },
    //更改试卷-->选择题型
    changeExaminationPaperId() {
      if (this.queryParam.examinationPaperId) {
        this.queryParamSelect.examPaperProjectItemIdSelect = 'ach_exam_paper_project_item,exa_pap_pro_item_name,id,iz_open =1 and del_flag  =0 and examination_paper_id= \'' + this.queryParam.examinationPaperId + '\' order by exa_pap_pro_item_order'
      }
    },
    //更改标准-->选择标准分项
    changeAchiStandPurposeType() {
      // if(this.queryParam.achiStandPurposeType){
      //   this.queryParamSelect.achieveStandardItemIdSelect = "ach_achieve_standard_item,stand_item_name,id,iz_open =1 and del_flag =0 and achievement_standard_id = \'"+this.queryParam.achiStandPurposeType+"\' order by exa_pap_pro_item_code" ;
      // }
      // this.changeExamPaperProjectItemId();
    },
    //更改科目或试卷-->更改试卷题型分项
    changeSubjectId() {
      if (this.queryParam.subjectId && this.queryParam.examinationId) {
        this.queryParamSelect.examinationPaperIdSelect = 'ach_examination_paper aep,aep.examination_paper_name ,aep.id,aep.iz_open =1  and aep.del_flag  = 0  and aep.subject_id =\'' + this.queryParam.subjectId + '\' and aep.examination_id =\'' + this.queryParam.examinationId + '\' order by aep.examination_id !! aep.examination_paper_order'
        // this.queryParamSelect.examPaperProjectItemIdSelect = "ach_exam_paper_project_item aeppi inner join ach_examination_paper aep on aeppi.examination_paper_id  = aep.id,aeppi.exa_pap_pro_item_name ,aeppi.id,aeppi.iz_open  =1 and aeppi.del_flag  = 0  and aep.examination_id  =\'"+this.queryParam.examinationId+"\'  and aep.subject_id = \'"+this.queryParam.subjectId+"\'  order by aeppi.exa_pap_pro_item_order"
      } else if (queryParam.examinationPaperId) {
        this.queryParamSelect.examinationPaperIdSelect = 'ach_examination_paper aep,aep.examination_paper_name ,aep.id,aep.iz_open =1  and aep.del_flag  = 0 and aep.examination_id =\'' + this.queryParam.examinationId + '\' order by aep.examination_id !! aep.examination_paper_order'
        // this.queryParamSelect.examPaperProjectItemIdSelect = "ach_exam_paper_project_item aeppi,aeppi.exa_pap_pro_item_name ,aeppi.id,aeppi.examination_paper_id  = \'"+this.queryParam.examinationPaperId+"\' order by aeppi.exa_pap_pro_item_order"
      }


    },
    //更改试卷题型分项-->更改标准分项（段位）
    changeExamPaperProjectItemId() {
      // if(this.queryParam.examPaperProjectItemId){
      //   this.queryParamSelect.achieveStandardItemIdSelect = "ach_achieve_standard_item aasi,aasi.stand_item_name ,aasi.id, aasi.exa_pap_pro_item_code  = \'"+this.queryParam.examPaperProjectItemId+"\' order by aasi.stand_item_order"
      // }
      // else
      if (this.queryParam.examPaperProjectItemId) {
        this.queryParamSelect.achieveStandardItemIdSelect = 'ach_achieve_standard_item aasi,aasi.stand_item_name ,aasi.id,aasi.iz_open =1 and aasi.del_flag  =0 and aasi.exa_pap_pro_item_code  = \'' + this.queryParam.examPaperProjectItemId + '\' order by aasi.stand_item_order'
      }
    },
    //查询条件联动end //////////////////////////////////////////////////////////////


    //动态列 script 1 ////////////////////////////////////////////////////////////////////////////////////////
    // 列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter(item => {
        if (item.key == 'rowIndex' || item.dataIndex == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      this.columns = cols
    },


    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
      this.settingColumns = []

      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function(item, i, array) {
          allSettingColumns.push(item.dataIndex)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (colSettings.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
    loadDataTrRow2ColInitColumns(testdata) {
      this.defColumns = [] //置空设置，防止重复设置
      this.columns = [] //置空设置，防止重复设置
      if (testdata == undefined || testdata == null) {
        var params = this.getQueryParams()//查询条件
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            testdata = res.result.records
            // this.loadDataTrRow2ColUtil3(testdata);
            this.loadDataTrRow2ColInitColumns(testdata)
          }
        })
      }
      //第一次遍历，制做 表头
      var th = []
      // th = this.gudingColumns; //表头 [{}] //浅拷贝
      //th = util.deepCopy(this.gudingColumns); //表头 [{}] //深拷贝
      // th = JSON.parse(JSON.stringify(this.gudingColumns)) //表头 [{}] //深拷贝1:该方法不能解决属性为函数，undefined，循环引用的的情况
      // th = cloneObject(this.gudingColumns) //深拷贝1

      // Object.assign([],th,this.gudingColumns) //表头 [{}] //深拷贝2:Object.assign 方法只会拷贝源对象自身的并且可枚举的属性到目标对象，继承属性和不可枚举属性是不能拷贝的。
      //针对深拷贝，需要使用其他办法，因为 Object.assign()拷贝的是属性值。假如源对象的属性值是一个对象的引用，那么它也只指向那个引用。
      //目前IE浏览器不兼容Object.assign()
      th = deepClone(this.gudingColumns)//表头 [{}] //深拷贝3:自定义递归函数解决深拷贝问题

      var thKeyCol = {} //动态关键列,需重新定义，动态获取


      //筛选科目分项
      var thKey = {}
      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        var dontaicolName = this.dongtaiColumns[0].dataIndex
        var dontaicolId = this.dongtaiColumns[0].dataIndexId
        if (d[dontaicolName] != undefined && d[dontaicolName] != null && d[dontaicolName] != 'null' && d[dontaicolName] != '') {
          // thKey[d[dontaicolName] ] =1 ;
          thKey[d[dontaicolName]] = d[dontaicolId]  //动态列

          // thKey[eval("d."+dontaicolId)] =2;
        } else if (d[dontaicolName] == null || d[dontaicolName] != 'null' || d[dontaicolName] != '') {
          thKey[this.dongtaiColumns[0].nulldatacolname] = this.dongtaiColumns[0].nulldatacolname  //动态列

        } else {
          thKey['-1'] = '-1'
        }

        // if(  d[dontaicolId] != undefined && d[dontaicolId] != null && d[dontaicolId] != 'null' && d[dontaicolId] != '' ){
        //   thKey[d[dontaicolId] ] = 2;  //动态列
        // }

      }

      //把科目加到th里面 ，动态增长列
      // for (var key in Object.keys(thKey))
      for (var key in thKey) {
        var colobj = { title: key, align: 'center', dataIndex: thKey[key] }
        th.push(colobj)
        thKeyCol[key] = key
      }
      // this.tableHeader = th;
      //重新定义列，增加动态列
      // if (this.defColumns == undefined || this.defColumns == null || this.defColumns.length ==0 ){
      //   this.defColumns = th;
      //   // this.initColumns();
      // }
      // if (this.columns == undefined || this.columns == null || this.columns.length ==0){
      //   this.columns = th;
      // }
      this.defColumns = th
      this.columns = th
      this.initColumns()
    },
    loadDataTrRow2ColInitDatas(testdata) {
      //第二次遍历，制做tr的行
      var tr = [] //数据 [{}]

      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        var rowdata = {}
        for (var j = 0; j < this.gudingColumns.length; j++) {
          rowdata[this.gudingColumns[j].dataIndex] = d[this.gudingColumns[j].dataIndex] //用对应列的数据赋值给固定列
        }


        //判断对象是否存在，存在则忽略，不存在则插入
        if (tr.length == 0) {
          tr.push(rowdata)
        } else {
          var insertflag = true
          for (var k in tr) {
            var eqflag = true
            for (var rd in rowdata) {
              if (rowdata[rd] !== tr[k][rd]) {
                eqflag = false
                continue
              }
            }
            //判断是否相等
            // if (Object.is(rowdata,tr[k])){
            // if ( this.compare(rowdata,tr[k]) ){
            if (eqflag) {
              insertflag = false
            } else {
              continue
            }
          }
          //应当插入则插入：即不存在则插入
          if (insertflag) {
            tr.push(rowdata)
          }
        }

      }
      //第三次遍历，添加科目的成绩:动态插入数据列
      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        //查找应该是tr的第几条数据
        var trindex = -1
        for (var ti = 0; ti < tr.length; ti++) {
          var tr_rowdata = tr[ti]//取出1条数据
          var equalflag = true
          for (var j = 0; j < this.gudingColumns.length; j++) {
            if (tr_rowdata[this.gudingColumns[j].dataIndex] != d[this.gudingColumns[j].dataIndex]) { //用对应列的数据赋值给固定列
              equalflag = false
            }
          }
          //如果相等即找到了,则写入数据,考虑动态列寻找
          if (equalflag) {
            //直接赋值：给对应动态列的值设置为成绩数值（会存在空值串列的情况，需考虑空值设置问题）
            //考虑到数据是通过列名绑定，就不会存在串列问题
            if (d[this.dongtaiColumns[0].dataIndexId] != undefined && d[this.dongtaiColumns[0].dataIndexId] != null && d[this.dongtaiColumns[0].dataIndexId] != '') {
              tr_rowdata[d[this.dongtaiColumns[0].dataIndexId]] = d[this.dongtaiColumns[0].valueIndex] + this.dongtaiColumns[0].valueIndexsuffix //把成绩数据绑定到动态列名上,加后缀单位
            } else {
              tr_rowdata[this.dongtaiColumns[0].nulldatacolname] = d[this.dongtaiColumns[0].valueIndex] + this.dongtaiColumns[0].valueIndexsuffix //把成绩数据绑定到动态列名上,加后缀单位
            }


            //通过循环判断，确定应该给哪个动态列赋值（避免空值串列问题）
            // for (var key in thKeyCol ){
            //   if (d[this.dongtaiColumns[0].dataIndex] == key ) {
            //     tr_rowdata[d[this.dongtaiColumns[0].dataIndexId]] = d[this.dongtaiColumnsValue[0].dataIndex] ;  //动态列的成绩数值
            //   }
            //   else if (tr_rowdata[key] == undefined || tr_rowdata[key] ==null || tr_rowdata[key] == ''){
            //     //补充其他学科为空值
            //     tr_rowdata[key] = null;
            //   }
            //   else if(tr_rowdata[key] != null){
            //     continue;//已经有值了，无需处理
            //   }
            //   else{
            //     //补充其他学科为-1异常情况
            //     tr_rowdata[key] = -1;
            //   }
            // }
          }
          tr[ti] = tr_rowdata //重新定义一行数据，把动态列数据加入进来
        }

      }

      this.dataSource = tr  //重新定义数据：用分组动态列进行行列转换后的新数据

    },
    async loadDataTrRow2Col() {
      //获得测试数据
      // var testdata = this.dataSource ;
      var testdata = []
      this.defColumns = []
      this.columns = []
      this.settingColumns = []

      var params = this.getQueryParams()//查询条件
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          testdata = res.result.records
          // this.loadDataTrRow2ColUtil3(testdata);
          this.loadDataTrRow2ColInitColumns(testdata) //列名已经初始化了，只需初始化1次，不必重复初始化
          this.loadDataTrRow2ColInitDatas(testdata)  //更新数据样式格式

        }
      })


    },
    searchQuery() {
      this.dataSource = []
      if (this.queryParam.classId) {
        this.loadDataTrRow2Col(1)
        // 点击查询清空列表选中行
        // https://gitee.com/jeecg/jeecg-boot/issues/I4KTU1
        this.selectedRowKeys = []
        this.selectionRows = []
      }
    },
    searchReset() {
      this.queryParam = {}
      this.loadDataTrRow2Col(1)
    },
    //
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadDataTrRow2Col()
    }
    //动态列 script 1 ////////////////////////////////////////////////////////////////////////////////////////
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>